import 'package:fish_redux/fish_redux.dart';
import 'package:kunlun_gas/app_files.dart';

import 'action.dart';
import 'state.dart';

Effect<OrderHistoryViewState> buildEffect() {
  return combineEffects(<Object, Effect<OrderHistoryViewState>>{
    // OrderHistoryViewAction.action: _onAction,
    Lifecycle.initState: _initState,
  });
}

void _onAction(Action action, Context<OrderHistoryViewState> ctx) {}

void _initState(Action action, Context<OrderHistoryViewState> ctx) async {
  ctx.state.items = [
    {
      'panoramagramImg':
          'https://znbc.oss-cn-beijing.aliyuncs.com/kunlun/drawings/2023/07/20 16:19:46/7ac6d3447c98a70a9e8ec9330a40d818.jpg,https://znbc.oss-cn-beijing.aliyuncs.com/kunlun/drawings/2023/07/20 16:20:05/b57fb87ac0cf1e28fb3c225dd670b1bd.jpg',
      'pipelineImg':
          'https://znbc.oss-cn-beijing.aliyuncs.com/kunlun/drawings/2023/07/20 16:19:50/198975dbeeb6c3fcded90f1c85523c03.jpg',
      'gasMeterImg':
          'https://znbc.oss-cn-beijing.aliyuncs.com/kunlun/drawings/2023/07/20 16:19:57/5e1c180cbdd5d40bee53c854198629de.jpg',
      'controllerType': '真兰(物联网表)',
      'qbNumber': '2380317737',
      'phone': '18001159960',
      "orderInfo": "商丘市示范区山水湖城23号楼2单元903",
      "name": "花鹏举",
      "successTime": "2023-07-20 16:21:08",
    }
  ];
  ResultData res = await CommonNetWork.checkHistoryList(ctx.state.userAccount);
  if (res.success) {
    List list = res.data['data'];
    if (list.isNotEmpty) {
      ctx.state.items.addAll(list
          .map((e) => CheckListItemModel.fromJson(
                e,
                '',
                '',
              ))
          .toList());
    }
  }
  ctx.dispatch(OrderHistoryViewActionCreator.onAction());
}
